import { DailyListNormal } from "./DailyListNormal";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../../mvc/ServerCommand";
import { Cache } from "../../../cache/Cache";
import { DailyRule } from "../../../rules/DailyRule";
import { CopyTitleBar } from "../titleBar/CopyTitleBar";
import { CopyAwardList } from "../reward/CopyAwardList";
import { ObjectPool } from "../../../../../com/gengine/utils/pools/ObjectPool";
import { DailyCopyItem } from "../item/DailyCopyItem";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
type int = number;
//class DailyCopyList
    
    export  class DailyCopyList extends DailyListNormal
    {
        constructor()
        {
            super();
            addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStageHandler);
            return;
        }

        protected onAddToStageHandler(arg1: Object /* flash.events.Event */): void
        {
            addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStageHandler);
            NetDispatcher.addCmdListener(ServerCommand.Copy_CopyNumInfoChange, this.onCopyNumInfoChange);
            return;
        }

        protected onRemoveFromStageHandler(arg1: Object /* flash.events.Event */): void
        {
            removeEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStageHandler);
            NetDispatcher.removeCmdListener(ServerCommand.Copy_CopyNumInfoChange, this.onCopyNumInfoChange);
            return;
        }

        protected onCopyNumInfoChange(arg1: Object): void
        {
            this.updateData(Cache.instance.daily.getListByType(DailyRule.TypeCopy), DailyRule.TypeCopy, this._subType);
            return;
        }

        protected /* override */ createTitleBar(): void
        {
            _titleBar = new CopyTitleBar(_titleWidth);
            _titleBar.x = 20;
            _titleBar.y = 5;
            addChild(_titleBar);
            return;
        }

        protected /* override */ createAwardList(): void
        {
            _dailyAwardList = new CopyAwardList(width - _listWidth - 4, height);
            _dailyAwardList.x = _listWidth + 4;
            _dailyAwardList.y = 0;
            addChild(_dailyAwardList);
            return;
        }

        protected /* override */ onItemListClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            super.onItemListClickHandler(arg1);
            if (_lastItem && _lastItem.info) 
            {
                this._subType = _lastItem.info.type;
            }
            return;
        }

        public /* override */ updateData(arg1: Array<any>, arg2: int, arg3: int=0): void
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            var loc4=null;
            this.dispose();
            if (arg1 != null) 
            {
                loc2 = arg1.length;
                while (loc1 < loc2) 
                {
                    loc3 = arg1[loc1];
                    loc4 = ObjectPool.getObject(DailyCopyItem);
                    if (loc3 != null) 
                    {
                        loc4.updateData(loc3);
                        _bodySprite.addItem(loc4);
                        if (loc1 == 0) 
                        {
                            _dailyAwardList.updateData(loc3);
                            loc4.mouseDown(true);
                            _lastItem = loc4;
                            this._subType = loc4.info.type;
                        }
                    }
                    ++loc1;
                }
                if (loc2 <= 4) 
                {
                    _scrollPane.verticalScrollPolicy = ScrollPolicy.OFF;
                }
                else 
                {
                    _scrollPane.verticalScrollPolicy = ScrollPolicy.AUTO;
                }
            }
            _bodySprite.redraw();
            _scrollPane.refreshPane();
            _scrollPane.update();
            _scrollPane.horizontalScrollPosition = 0;
            selectedItemByType(arg3);
            return;
        }

        public /* override */ dispose(): void
        {
            super.dispose();
            this._subType = 0;
            return;
        }

        protected /* var */_subType: int;
    }
